package com.book.service.serviceImpl;

import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.book.entity.Book;
import com.book.mapper.BookMapper;
import com.book.request.getHotBookReq;
import com.book.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl extends ServiceImpl<BookMapper,Book> implements BookService {
    @Autowired
    BookMapper bookMapper;

    @Override
    public List<Book> getRecommendBooks() {
        Wrapper<Book> con=new Condition();
        con.eq("recommend","1");
        return  selectList(con);
    }

    @Override
    public List<Book> getHotBooks(getHotBookReq request) {
        Wrapper<Book> con=new Condition();
        Page page=new Page();
        page.setCurrent(request.getCurrent());
        page.setSize(request.getSize());
        return selectPage(page,con).getRecords();
    }

    @Override
    public Page getBooksByCId(String cId, int current, int size) {
        Wrapper<Book> con=new Condition();
        con.eq("c_id",cId);
        Page page=new Page();
        page.setSize(size);
        page.setCurrent(current);
        return selectPage(page,con);
    }

    @Override
    public List<Book> search(String keyword) {
        return bookMapper.search(keyword);
    }
}
